package com.work.customer.task;


import com.work.customer.dao.CustomerMapper;
import com.work.customer.pojo.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;



/*秒杀定时任务*/
@Component
public class CustomerTask {

    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 定时查询数据库数据
     * 暂定为24h一次，每天12点触发
     */
    @Scheduled(cron = "0 0 12 * * ? ")
    public void customerTask() {
        List<Customer> customers = customerMapper.selectAll();
        for (Customer customer : customers) {
            //获取农场组织的到期时间
            Date endTime = customer.getEndTime();
            //获取当前时间
            Date date = new Date();
            //判断大小
            if(date.getTime()>endTime.getTime()){
                //如果当前时间大于到期时间,则将农场组织状态改为停用-1
                customer.setStatus("-1");
                customerMapper.updateByPrimaryKey(customer);
            }
        }

    }
}
